function [xvariable yvariable]=PrepareRegressX(TotalData,resReturn,dayperquarter,varargin)
vec_x=[];price=TotalData(:,3:5);retvet=TotalData(:,1);volume=TotalData(:,2);
[mat_XX window] = patternRec3(price(1:end-1,3));

try
    % ADX indicator
    [vout]=indicators(price(1:end-1,:),'adx',3);
    mat_XX = [mat_XX vout(window:end,3)];
    [vout]=indicators(price(1:end-1,:),'adx',15);
    mat_XX = [mat_XX vout(window:end,3)];
    
    % Stochastic Oscillator (Base on
    [vout1]=indicators(price(1:end-1,:),'fsto',3,3);
    mat_XX = [mat_XX vout1(window:end,:)];
    
    [vout2]=indicators(price(1:end-1,:),'fsto',15,3);
    mat_XX = [mat_XX vout2(window:end,:)];
    mat_XX = [mat_XX vout1(window:end,:)./vout2(window:end,:)];
    
    % momentum (rate of change)
    [vout1]=indicators(price(1:end-1,3),'roc',3);
    mat_XX = [mat_XX vout1(window:end)];
    
    [vout2]=indicators(price(1:end-1,3),'roc',15);
    mat_XX = [mat_XX vout2(window:end)];
    mat_XX = [mat_XX vout1(window:end)./vout2(window:end)];
    
    % relative strength index
    
    [vout1]=indicators(price(1:end-1,3),'rsi',3);
    mat_XX = [mat_XX vout1(window:end)];
    
    [vout2]=indicators(price(1:end-1,3),'rsi',15);
    mat_XX = [mat_XX vout2(window:end)];
    
    mat_XX = [mat_XX vout1(window:end)./vout2(window:end)];
    
    
    % macd
    [vout1]=indicators(price(1:end-1,3),'macd');
    mat_XX = [mat_XX vout1(window:end,1)];
    
    %average true range
    [vout1]=indicators(price(1:end-1,:),'atr',3);
    %     mat_XX = [mat_XX vout1(window:end)];
    
    [vout2]=indicators(price(1:end-1,:),'atr',15);
    %     mat_XX = [mat_XX vout2(window:end)];
    mat_XX = [mat_XX vout1(window:end)./vout2(window:end)];
    
    
    % simple moving average
    
    [vout1]=indicators(price(1:end-1,3),'sma',3);
    %     mat_XX = [mat_XX vout1(window:end)];
    
    [vout2]=indicators(price(1:end-1,3),'sma',15);
    %     mat_XX = [mat_XX vout2(window:end)];
    mat_XX = [mat_XX vout1(window:end)./vout2(window:end)];
    vout1=[];vout2=[];
    
    % simple moving average (volume)
    
    [vout1]=indicators(volume(1:end-1),'sma',3);
    %     mat_XX = [mat_XX vout1(window:end)];
    
    [vout2]=indicators(volume(1:end-1),'sma',15);
    %     mat_XX = [mat_XX vout2(window:end)];
    mat_XX = [mat_XX vout1(window:end)./vout2(window:end)];
    vout1=[];vout2=[];
    if ~isempty(varargin{1})
        mat_XX=horzcat(mat_XX,[price(window:1:end-1,3)]);
    end
catch
    mat_XX=[];
end
% Calculate real residual
ttt=length(retvet(:,1));
if window>ttt   %This is to prevent the case of revet vector length lower than the window
    window=ttt;
end
try
    yvariable=maniArray(resReturn,dayperquarter);
    yvariable(1:window+(length(yvariable)>length(retvet)))=[];
    yvariable=yvariable-retvet(window+1:end);
catch
    yvariable=resReturn-retvet(window+1:end)';
end
% Remove window part
if size(mat_XX,2)==29;
    
    vec_x=[vec_x;mat_XX];
else
    yvariable(1:end)=[];
    vec_x=[];
    %         zz(i,1)=size(vec_x,1);-+
end
xvariable=vec_x;
end
